package com.cy.pj.sys.web.service.Impl;


import com.cy.pj.sys.dao.SysLogDao;
import com.cy.pj.sys.pojo.SysLog;
import com.cy.pj.sys.web.common.annotation.RequiredLog;
import com.cy.pj.sys.web.common.annotation.RequiredTime;
import com.cy.pj.sys.web.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(
        readOnly = false,
        timeout = 60,
        rollbackFor = Throwable.class,
        isolation = Isolation.READ_COMMITTED)
@Service
public class SysLogServiceImpl implements SysLogService {
    @Autowired
    private SysLogDao sysLogDao;
    @Async
    @Override
    public void saveLog(SysLog sysLog) {
        System.out.println("saveLog->"+Thread.currentThread().getName());
        sysLogDao.insertLog(sysLog);
        try {
            Thread.sleep(10000);
        } catch (Exception e) {
        }
    }
    @Transactional
    @RequiredLog(operation = "删除日志")
    @Override
    public int deleteById(Long... id) {
//        for (int i = 0; i < id.length; i++) {
//            if (i==1){
//                throw  new RuntimeException("删除失败");
//            }
//            sysLogDao.deleteById(id[i]);
//        }
//            return 10;
        int rows=sysLogDao.deleteById(id);
        return rows;



    }

    @Override
    public SysLog findById(Long id) {

        SysLog log=sysLogDao.selectById(id);
        return log;
    }
    @Transactional(readOnly = true)
    @RequiredTime(operation = "公告时间")
    @RequiredLog(operation = "公告查询")
    @Override
    public List<SysLog> findLogs(SysLog sysLog) {
        System.out.println("findLogs->"+Thread.currentThread().getName());
        List<SysLog> list=sysLogDao.selectLogs(sysLog);
        return list;
//        throw  new RuntimeException("没有找到相应的记录");
    }


}